﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntityObjects;
using DAL_V1.App_Code.DBBroker;
using BAL.Controller;
using System.Data;
using System.Data.SqlClient;

namespace PresentationLayer.View
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        String varEmpName;
        Employee loginDepHead = new Employee();
        private List<Employee> empe_list = new List<Employee>(); 

        protected void Page_Load(object sender, EventArgs e)
        {

            //GvEmpList.DataSource = EmployeeDBBroker.getEmployeeDBBroker().selectAllEmployee();
            //GvEmpList.DataBind();

          // **** respective Department Employee will be displayed.*************
            
            Employee loginDepHead = new Employee();
            loginDepHead = (Employee)Session["CurrentUser"];
            GvEmpList.DataSource = DelHeadAuthorityController.getDelHeadAuthorityController().selectEmployeeByDept(loginDepHead.DeptId.ToString());
            GvEmpList.DataBind();
            varEmpName = txtEmpName.Text;
        }



        protected void GvEmpList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GvEmpList.PageIndex = e.NewPageIndex;
            GvEmpList.DataBind();

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
          
            
            Employee empe = new Employee();
            empe = (Employee)Session["CurrentUser"];
            string Depname = empe.DeptId;

             GvEmpList.DataSource = DelHeadAuthorityController.getDelHeadAuthorityController().getEmployeebyDeptIdAndEmpName(Depname, txtEmpName.Text);
             GvEmpList.DataBind();

            //string cs1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SSIS.mdf;Integrated Security=True;User Instance=True";

            //String testquery = " Select EmpId, EmpName from Employee where DeptId='" + Convert.ToString(test.DeptId) + "' and EmpName like'%" + varEmpName + "%'";
            //SqlDataAdapter adapt1 = new SqlDataAdapter(testquery, cs1);
            //DataSet dataSet = new DataSet();
            //adapt1.Fill(dataSet);
            //DataTable dt1 = dataSet.Tables[0];
            //GvEmpList.DataSource = dataSet;
            //GvEmpList.DataBind();

        }

        //Assign Department Head Authority to Selected Employee ( Roleid " 1" )
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string selectedid = Request.Form["Empid"];
            lblmessage.Visible = true;
            lblmessage.Text = selectedid;

            Employee emp = new Employee();
            emp.RoleId = 1;



            int result = DelHeadAuthorityController.getDelHeadAuthorityController().updateEmployee(emp, selectedid);

           // lblmessage.Text=

            //string cs1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SSIS.mdf;Integrated Security=True;User Instance=True";

            //String updatequery = " update Employee set Role='" + Convert.ToString(test.DeptId) + "' and EmpName like'%" + EmpInitial + "%'";
            //SqlDataAdapter adapt1 = new SqlDataAdapter(testquery, cs1);

            
            
            
            }
          
        
    }
}